package com.subl.controller;

import com.subl.component.PrintBeans;
import com.subl.pojo.User;
import com.subl.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@RestController
public class HelloController {
    @Autowired
    private PrintBeans printBeans;
    @Autowired
    private UserService userService;


    @GetMapping("/hello")
    public String sayHello() {
        return "hello world!";
    }


    @GetMapping("/bean-list")
    public Map<String, String> showBeanList() {
        return printBeans.getBeanList();
    }

    @GetMapping("/export-data")
    public String exportData() {
        String s = userService.doTransUser();
        return s;
    }

    @GetMapping("/user-list")
    public List<User> getUserList() throws SQLException {
        List<User> userList = printBeans.getUserList();
        return userList;
    }

    @GetMapping("/user-list2")
    public List<User> getUserList2() throws SQLException {
        List<User> userList = userService.getUserList();
        return userList;
    }

    @GetMapping("/update-user")
    public String updateUser() {
        return userService.updateUser();
    }
}
